const app = getApp();
import grace from "../../../utils/grace.js";

grace.page({
  /**
   * 页面的初始数据
   */
  data: {
    student_id: 0,
    accept_card: '',
    card: 0
  },
  onLoad(e){
    this.$data.student_id = e.student_id;
    this.$data.card = e.card;
  },
  formSubmit(e) {
    let that = this;

    if (e.detail.value.accept_card == '') {
      wx.showToast({
        title: '卡号不能为空',
        icon: 'fail',
        duration: 1000
      })

      return false;
    }

    let token = wx.getStorageSync('token');
    wx.showLoading({
      title: '加载中...',
    })
    let url = app.globalData.api + '/api/v1.0/student/ferry/' + that.$data.student_id;
    let params = {
      token: token,
      operate: 'new',
      card: that.$data.card,
      ferry_code: e.detail.value.accept_card,
      ferry_code_ref: e.detail.value.ferry_code_ref
    }
    that.$http.put(url, params).then((res) => {
      if (res.data.code == 0) {
        that.$goBack();
      }else{
        wx.showModal({
          title: '错误',
          content: res.data.msg,
          showCancel: false
        })
      }
      wx.hideLoading();
    })
  }
})